package com.qf.air.controller;

import com.qf.air.entity.AirQualityIndex;
import com.qf.air.entity.District;
import com.qf.air.service.DistrictService;
import com.qf.air.vo.AirVO;
import com.qf.air.vo.DistrictVO;
import com.qf.air.vo.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zjw
 * @description 区域的Controller层
 * @date 2021/10/8 17:07
 */
@RestController
@RequestMapping("/district")
@CrossOrigin
public class DistrictController {

    @Autowired
    private DistrictService districtService;

    @GetMapping("/list")
    public R list(){
        // 查询数据
        List<District> list = districtService.findAll();

        // 封装数据
        List<DistrictVO> data = new ArrayList<>();
        for (District district : list) {
            DistrictVO vo = new DistrictVO();
            BeanUtils.copyProperties(district,vo);
            data.add(vo);
        }

        // 返回
        return R.ok(data);
    }

    /*
    # 查询首页展示的全部区域信息

    # 响应数据
    # 成功
    {
        "code": 0,
        "msg": "",
        "data": [
            {"id": 1,"name": "东城区"},
            {"id": 2,"name": "男城区"},
            {"id": 3,"name": "洗城区"},
            {"id": 4,"name": "被城区"},
            {"id": 5,"name": "中城区"}
        ]
    }
    # 失败
    {
        "code": 888,
        "msg": "服务器挤爆了，请稍后再试！"
    }
     */

}
